package com.tjsinfo.tjsoa.system.bo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.Criteria;
import org.hibernate.annotations.FetchMode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.Dao.ISpringDao;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.documentationflow.dangweifawen.vo.TDangweifawenNeirong;
//import com.tjsinfo.tjsoa.documentationflow.tongzhifawen.vo.TTongzhifawenNeirong;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.TXingzhengfawenNeirong;
import com.tjsinfo.tjsoa.system.dao.ISystemUserDao;
import com.tjsinfo.tjsoa.system.vo.TSysUser;
import com.tjsinfo.tjsoa.system.vo.TSystemDepartment;
import com.tjsinfo.tjsoa.system.vo.TSystemDuty;
import com.tjsinfo.tjsoa.system.vo.TSystemPost;
import com.tjsinfo.tjsoa.system.vo.TSystemRolesGroup;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.TSystemUserDepartment;
import com.tjsinfo.tjsoa.system.vo.TSystemUserDuty;
import com.tjsinfo.tjsoa.system.vo.TSystemUserPost;
import com.tjsinfo.tjsoa.system.vo.TSystemUserRole;
import com.tjsinfo.tjsoa.system.vo.TSystemUserRoleGroup;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.workflow.WorkFlowTemplate;

public class SystemUserBo implements ISystemUserBo{
	private ISystemUserDao systemUserDao;
	private IQbcDao qbcDao;
	private ITSystemUserRoleGroupBO systemUserRoleGroupBO;
	private ISystemUserDepartmentBo systemUserDepartmentBo;
	private ISystemUserDutyBo systemUserDutyBo;
	private ISystemUserPostBO systemUserPostBO;
	private ISystemUserRoleBO systemUserRoleBO;
	private ISystemDutyBo systemDutyBo;
	private IDepartmentBo departmentBo;
	private ITSystemRolesGroupBO systemRolesGroupBO;
//	private ISpringDao rQSOAAspringDao;
//	private ISpringDao rQSOABspringDao;
//	private ISpringDao rQSOACspringDao;
//	private ISpringDao rQSOAsspringDao;
	private ISpringDao springDao;
	
	
	
	public ISpringDao getSpringDao() {
		return springDao;
	}

	public void setSpringDao(ISpringDao springDao) {
		this.springDao = springDao;
	}

//	public ISpringDao getRQSOAAspringDao() {
//		return rQSOAAspringDao;
//	}
//
//	public void setRQSOAAspringDao(ISpringDao aspringDao) {
//		rQSOAAspringDao = aspringDao;
//	}
//
//	public ISpringDao getRQSOABspringDao() {
//		return rQSOABspringDao;
//	}
//
//	public void setRQSOABspringDao(ISpringDao bspringDao) {
//		rQSOABspringDao = bspringDao;
//	}
//
//	public ISpringDao getRQSOACspringDao() {
//		return rQSOACspringDao;
//	}
//
//	public void setRQSOACspringDao(ISpringDao cspringDao) {
//		rQSOACspringDao = cspringDao;
//	}
//
//	public ISpringDao getRQSOAsspringDao() {
//		return rQSOAsspringDao;
//	}
//
//	public void setRQSOAsspringDao(ISpringDao asspringDao) {
//		rQSOAsspringDao = asspringDao;
//	}

	public ITSystemRolesGroupBO getSystemRolesGroupBO() {
		return systemRolesGroupBO;
	}

	public void setSystemRolesGroupBO(ITSystemRolesGroupBO systemRolesGroupBO) {
		this.systemRolesGroupBO = systemRolesGroupBO;
	}

	public IDepartmentBo getDepartmentBo() {
		return departmentBo;
	}

	public void setDepartmentBo(IDepartmentBo departmentBo) {
		this.departmentBo = departmentBo;
	}

	public ISystemUserRoleBO getSystemUserRoleBO() {
		return systemUserRoleBO;
	}

	public void setSystemUserRoleBO(ISystemUserRoleBO systemUserRoleBO) {
		this.systemUserRoleBO = systemUserRoleBO;
	}

	public ITSystemUserRoleGroupBO getSystemUserRoleGroupBO() {
		return systemUserRoleGroupBO;
	}

	public void setSystemUserRoleGroupBO(
			ITSystemUserRoleGroupBO systemUserRoleGroupBO) {
		this.systemUserRoleGroupBO = systemUserRoleGroupBO;
	}

	public ISystemUserDepartmentBo getSystemUserDepartmentBo() {
		return systemUserDepartmentBo;
	}

	public void setSystemUserDepartmentBo(
			ISystemUserDepartmentBo systemUserDepartmentBo) {
		this.systemUserDepartmentBo = systemUserDepartmentBo;
	}

	public ISystemUserDutyBo getSystemUserDutyBo() {
		return systemUserDutyBo;
	}

	public void setSystemUserDutyBo(ISystemUserDutyBo systemUserDutyBo) {
		this.systemUserDutyBo = systemUserDutyBo;
	}

	public ISystemUserPostBO getSystemUserPostBO() {
		return systemUserPostBO;
	}

	public void setSystemUserPostBO(ISystemUserPostBO systemUserPostBO) {
		this.systemUserPostBO = systemUserPostBO;
	}

	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	public ISystemUserDao getSystemUserDao() {
		return systemUserDao;
	}

	public void setSystemUserDao(ISystemUserDao systemUserDao) {
		this.systemUserDao = systemUserDao;
	}

	public Integer addSystemUser(TSystemUser systemUser) {
		// TODO Auto-generated method stub
		return systemUserDao.save(systemUser);
	}

	public Boolean deleteSystemUser(Integer systemUserId) {
		// TODO Auto-generated method stub
		TSystemUser systemUser = findByIdSystemUser(systemUserId);
		Byte state = 1;
		systemUser.setState(state);
		return  updateSystemUser(systemUser);
		
	}

	public TSystemUser findByIdSystemUser(Integer id) {
		// TODO Auto-generated method stub
		return systemUserDao.findById(id);
	}

	public String findByIdUser(Integer id,String password) {
		// TODO Auto-generated method stub
		TSystemUser a = systemUserDao.findById(id);
		if(password.equals(a.getPassword()))return "true";
		else return "false";
	}
	
	public List<TSystemUser> selectAllSystemUser(Integer first, Integer max) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.asc("orderNo"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
		 
	}
	public List<TSystemUser> selectQiyongSystemUser(Integer first, Integer max,Byte state) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		detachedCriteria.add(Restrictions.eq("state", state));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.asc("orderNo"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
		 
	}
	public List<TSystemUser> selectTingyongSystemUser(Integer first, Integer max,Byte state) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		detachedCriteria.add(Restrictions.eq("state", state));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.asc("orderNo"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
		 
	}

	public List<TSystemUser> selectSystemUserByLikeUsername(String username,
			Integer first, Integer max) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		detachedCriteria.add(Restrictions.like("userName", "%"+username+"%"));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.asc("orderNo"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}

	public Integer selectSytemUserLikeUsernameTotalLine(String username) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		detachedCriteria.add(Restrictions.like("userName", "%"+username+"%"));
		return  qbcDao.getQueryNumber(detachedCriteria, "userId");
	}

	public Integer selectSytemUserLikeUserIdTotalLine(Integer userId) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		detachedCriteria.add(Restrictions.eq("userId", userId));
		return  qbcDao.getQueryNumber(detachedCriteria, "userId");
	}
	public Integer selectSytemUserRoleGroupTotalLine(Integer roleGroupId) {
		List<TSystemUserRoleGroup> systemUserRoleGroupList = systemUserDao.selectGroupsByRoleGroup(roleGroupId);
		return systemUserRoleGroupList.size();
	}
	public Integer selectSytemUserTotalLine() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		return  qbcDao.getQueryNumber(detachedCriteria, "userId");
	}
	public Integer selectQiyongUserTotalLine() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		detachedCriteria.add(Restrictions.eq("state", (byte) 0));
		return  qbcDao.getQueryNumber(detachedCriteria, "userId");
	}
	public Integer selectTingyongUserTotalLine() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUser.class);
		detachedCriteria.add(Restrictions.eq("state", (byte) 1));
		return  qbcDao.getQueryNumber(detachedCriteria, "userId");
	}

	public Boolean updateSystemUser(TSystemUser systemUser) {
		// TODO Auto-generated method stub
		return systemUserDao.update(systemUser);
	}
	
	public Boolean intoSystemUser(Integer systemUserId){
		TSystemUser systemUser = findByIdSystemUser(systemUserId);
		if (systemUser.getState() == 1) {
			Byte state = 0;
			systemUser.setState(state);
		} else {
			Byte state = 1;
			systemUser.setState(state);
		}
		return  updateSystemUser(systemUser);
	}

	public Boolean isUser(HttpServletRequest request) {
		// TODO Auto-generated method stub
		try {
			String loginName = request.getParameter("loginName");
			String password = request.getParameter("password");
			DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
			criteria.add(Restrictions.eq("loginName", loginName));
			criteria.add(Restrictions.eq("password", password));
			Byte state = 0;
			criteria.add(Restrictions.eq("state", state));
			List<TSystemUser> userList = qbcDao.getCriteria(criteria);
			if (userList.size() > 0) {
				User user=new User();
				TSystemUser systemUser=userList.get(0);
				user.setUser_id(systemUser.getUserId());
				user.setUUID(systemUser.getUuid());
				user.setUsername(systemUser.getUserName());
				user.setType(0);
				request.getSession().setAttribute("user", user);
				request.getSession().setAttribute("id", user.getUser_id());
				return true;
			} else {
				return false;
			}
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}

	public List<TSystemUser> selectByDepartment(String departmentId) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserDepartment.class);
		criteria.add(Restrictions.eq("departmentId", departmentId));
		List<TSystemUserDepartment> systemUserDepartmentList = qbcDao.getCriteria(criteria);
		List<TSystemUser> list = new ArrayList<TSystemUser>();
		for (TSystemUserDepartment systemUserDepartment : systemUserDepartmentList) {
			TSystemUser systemUser = systemUserDao.findById(systemUserDepartment.getUserId());
			if(systemUser != null && systemUser.getState() != 1){
				list.add(systemUser);
			}
			
		}
		Comparator comp = new Comparator(){
	          public int compare(Object o1,Object o2) {
	        	  TSystemUser p1=(TSystemUser)o1;
	        	  TSystemUser p2=(TSystemUser)o2; 
	             if(p1.getOrderNo()>p2.getOrderNo())
	                 return 1;
	             else
	                 return 0;
	             }
	        };
	        Collections.sort(list, comp);
		return list;
	}

	/**
	 * 根据部门ID查找非删除的用户用户
	 * @param 部门ID
	 * @return
	 */
	public List<TSystemUser> selectByDepartmentNotDel(String departmentId){
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserDepartment.class);
		criteria.add(Restrictions.eq("departmentId", departmentId));
		List<TSystemUserDepartment> systemUserDepartmentList = qbcDao.getCriteria(criteria);
		List<TSystemUser> list = new ArrayList<TSystemUser>();
		for (TSystemUserDepartment systemUserDepartment : systemUserDepartmentList) {
			TSystemUser systemUser = systemUserDao.findById(systemUserDepartment.getUserId());
			if(systemUser != null && systemUser.getState() == 0){
				list.add(systemUser);
			}
			
		}
		Comparator comp = new Comparator(){
	          public int compare(Object o1,Object o2) {
	        	  TSystemUser p1=(TSystemUser)o1;
	        	  TSystemUser p2=(TSystemUser)o2; 
	             if(p1.getOrderNo()>p2.getOrderNo())
	                 return 1;
	             else
	                 return 0;
	             }
	        };
	        Collections.sort(list, comp);
		return list;
	}
	
	public List<TSystemUser> selectByDuty(String dutyId) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserDuty.class);
		criteria.add(Restrictions.eq("dutyId", dutyId.trim() ));
		List<TSystemUserDuty> systemUserDutyList = qbcDao.getCriteria(criteria);
		List<TSystemUser> list = new ArrayList<TSystemUser>();
		for (TSystemUserDuty systemUserDuty : systemUserDutyList) {
			TSystemUser systemUser = systemUserDao.findById(systemUserDuty.getUserId());
			list.add(systemUser);
		}
		return list;
	}
	
	
	public List<TSystemUser> selectByDutyName(String dutyName){
		
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemDuty.class);
		criteria.add(Restrictions.eq("dutyName", dutyName ));
		List<TSystemDuty> systemdutylist =	qbcDao.getCriteria(criteria);
		
		if (systemdutylist.size() >0) {
			TSystemDuty systemDuty =  systemdutylist.get(0);
			return selectByDuty(systemDuty.getDutyId());
		}
		else
		{
			return	new ArrayList<TSystemUser>();
		}
		
		
	}
	public List<TSystemUser> selectByPost(String postId) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserPost.class);
		criteria.add(Restrictions.eq("postId", postId));
		List<TSystemUserPost> systemUserPostList = qbcDao.getCriteria(criteria);
		List<TSystemUser> list = new ArrayList<TSystemUser>();
		for (TSystemUserPost systemUserPost : systemUserPostList) {
			TSystemUser systemUser = systemUserDao.findById(systemUserPost.getUserId());
			list.add(systemUser);
		}
		return list;
	}

	public List<TSystemUser> selectByRloesGroup(Integer rloesGroupId) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserRoleGroup.class);
		criteria.add(Restrictions.eq("roleGroupId", rloesGroupId));
		List<TSystemUserRoleGroup> systemUserRoleGroupList = qbcDao.getCriteria(criteria);
		List<TSystemUser> list = new ArrayList<TSystemUser>();
		for (TSystemUserRoleGroup systemUserRoleGroup : systemUserRoleGroupList) {
			TSystemUser systemUser = systemUserDao.findById(systemUserRoleGroup.getUserId());
			list.add(systemUser);
		}
		return list;
	}

	public List<TSystemUser> selectByUserRolesGroup(Integer roleGroupId,
			Integer first, Integer max) {
		// TODO Auto-generated method stub
//		List<TSystemUserRoleGroup> systemUserRoleGroupList = systemUserDao.selectByRoleGroup(roleGroupId);
//		List<TSystemUser> list = new ArrayList<TSystemUser>();
//		for (int i=first;i<(first+15<systemUserRoleGroupList.size()?first+15:systemUserRoleGroupList.size());i++){
//			TSystemUserRoleGroup systemUserRoleGroup = systemUserRoleGroupList.get(i);
//			TSystemUser systemUser = systemUserDao.findById(systemUserRoleGroup.getUserId());
//			if(systemUser != null){				
//				list.add(systemUser);
//			}			
//		}	
		List<TSystemUser> listre = systemUserDao.selectByRoleGroup(roleGroupId);
		List<TSystemUser> list = new ArrayList<TSystemUser>();
		for(int i=first;i<(first+15<listre.size()?first+15:listre.size());i++){
			TSystemUser systemUser = listre.get(i);
			list.add(systemUser);
		}
		return list;
	}

	public Integer singerSystemUser(TSystemUser systemUser,
			String departmentid, String dutyid, String postid,
			String rloesGroupid,String rolesid) {
		// TODO Auto-generated method stub
		systemUser.setUuid(ToolKit.getUUID());
		Integer id = addSystemUser(systemUser);
		String[] departmentidarray = departmentid.split(",");
		String[] dutyidarray = dutyid.split(",");
		String[] postidarray = postid.split(",");
		if (rloesGroupid != null&&!"".equals(rloesGroupid)) {
			String[] rloesGroupidarray = rloesGroupid.split(",");
			for (int i = 0; i < rloesGroupidarray.length; i++) {
				TSystemUserRoleGroup systemUserRoleGroup = new TSystemUserRoleGroup();
				systemUserRoleGroup.setRoleGroupId(Integer.parseInt(rloesGroupidarray[i]));
				systemUserRoleGroup.setUserId(id);
				systemUserRoleGroupBO.addUserRoleGroup(systemUserRoleGroup);
			}
		}
		
		String[] rolesidarray = rolesid.split(",");
		for (int i = 0; i < departmentidarray.length; i++) {
			TSystemUserDepartment  userDepartment = new TSystemUserDepartment();
			userDepartment.setDepartmentId(departmentidarray[i]);
			userDepartment.setUserId(id);
			systemUserDepartmentBo.addSystemUserDepartment(userDepartment);
			TSystemDepartment systemDepartment =	departmentBo.findById(departmentidarray[i]);
			systemDepartment.setRemarks(String.valueOf(Integer.parseInt(systemDepartment.getRemarks()) + 1));
			departmentBo.update(systemDepartment);
			while(true)
			{
				if(!"0".equals(systemDepartment.getParentId()))
				{
					systemDepartment = departmentBo.findById(systemDepartment.getParentId());
					systemDepartment.setRemarks(String.valueOf(Integer.parseInt(systemDepartment.getRemarks()) + 1));
					departmentBo.update(systemDepartment);
				}
				else
				{
					break;
				}
			}
		}
		for (int i = 0; i < dutyidarray.length; i++) {
			TSystemUserDuty systemUserDuty = new TSystemUserDuty();
			systemUserDuty.setDutyId(dutyidarray[i]);
			systemUserDuty.setUserId(id);
			systemUserDutyBo.addSystemUserDuty(systemUserDuty);
		}
		for (int i = 0; i < postidarray.length; i++) {
			if(postidarray[i] !=null &&!"".equals(postidarray[i]))
			{
				TSystemUserPost systemUserPost = new TSystemUserPost();
				systemUserPost.setPostId(postidarray[i]);
				systemUserPost.setUserId(id);
				systemUserPostBO.addSystemUserPost(systemUserPost);
			}
		
		}
		
		for (int i = 0; i < rolesidarray.length; i++) {
			if(rolesidarray[i] !=null &&!"".equals(rolesidarray[i]))
			{
				TSystemUserRole systemUserRole = new TSystemUserRole();
				systemUserRole.setRoleId(Integer.parseInt(rolesidarray[i]));
				systemUserRole.setUserId(id);
				systemUserRoleBO.addSystemUserRole(systemUserRole);
			}			
		}
		return id;
	}

	public Boolean alterSystemUser(TSystemUser systemUser, String departmentid,
			String dutyid, String postid, String rloesGroupid, String rolesid,Integer ischang) {
		// TODO Auto-generated method stub
		try {
			Integer userId = systemUser.getUserId();
			String[] departmentidarray = departmentid.split(",");
			String[] dutyidarray = dutyid.split(",");
			String[] postidarray = postid.split(",");
			systemUserRoleGroupBO.deleteUserRoleGroupByUserId(userId);
			if (rloesGroupid != null&&!"".equals(rloesGroupid)) {
				String[] rloesGroupidarray = rloesGroupid.split(",");
				for (int i = 0; i < rloesGroupidarray.length; i++) {
					TSystemUserRoleGroup systemUserRoleGroup = new TSystemUserRoleGroup();
					systemUserRoleGroup.setRoleGroupId(Integer.parseInt(rloesGroupidarray[i]));
					systemUserRoleGroup.setUserId(userId);
					systemUserRoleGroupBO.addUserRoleGroup(systemUserRoleGroup);
				}
			}
			
			String[] rolesidarray = rolesid.split(",");
			systemUserDepartmentBo.deleteSystemUserDepartmentById(userId);
			systemUserDutyBo.deleteSysetemUserDutypByUserId(userId);
			systemUserPostBO.deleteSystemUserPostByUserId(userId);
		
			
			updateSystemUser(systemUser);
			for (int i = 0; i < departmentidarray.length; i++) {
				TSystemUserDepartment  userDepartment = new TSystemUserDepartment();
				userDepartment.setDepartmentId(departmentidarray[i]);
				userDepartment.setUserId(userId);
				systemUserDepartmentBo.addSystemUserDepartment(userDepartment);
				TSystemDepartment systemDepartment =	departmentBo.findById(departmentidarray[i]);
				systemDepartment.setRemarks(String.valueOf(Integer.parseInt(systemDepartment.getRemarks()) + 1));
				departmentBo.update(systemDepartment);
				while(true)
				{
					if(!"0".equals(systemDepartment.getParentId()))
					{
						systemDepartment = departmentBo.findById(systemDepartment.getParentId());
						systemDepartment.setRemarks(String.valueOf(Integer.parseInt(systemDepartment.getRemarks()) + 1));
						departmentBo.update(systemDepartment);
					}
					else
					{
						break;
						
					}
				}
				
			}
			for (int i = 0; i < dutyidarray.length; i++) {
				TSystemUserDuty systemUserDuty = new TSystemUserDuty();
				systemUserDuty.setDutyId(dutyidarray[i]);
				systemUserDuty.setUserId(userId);
				systemUserDutyBo.addSystemUserDuty(systemUserDuty);
			}
			for (int i = 0; i < postidarray.length; i++) {
				if(postidarray[i] !=null &&!"".equals(postidarray[i]))
				{
					TSystemUserPost systemUserPost = new TSystemUserPost();
					systemUserPost.setPostId(postidarray[i]);
					systemUserPost.setUserId(userId);
					systemUserPostBO.addSystemUserPost(systemUserPost);
				}
				
			}
			if(ischang  !=0){
				systemUserRoleBO.deleteSystemUserRoleByUserid(userId);
				for (int i = 0; i < rolesidarray.length; i++) {
					if(rolesidarray[i] !=null &&!"".equals(rolesidarray[i]))
					{
						TSystemUserRole systemUserRole = new TSystemUserRole();
						systemUserRole.setRoleId(Integer.parseInt(rolesidarray[i]));
						systemUserRole.setUserId(userId);
						systemUserRoleBO.addSystemUserRole(systemUserRole);
					}			
				}
			}			
			return true;
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}

	public Boolean isSameLoginName(String loginname) {
		// TODO Auto-generated method stub
		/*StringBuffer sqla = new StringBuffer("SELECT * FROM RQOAA.dbo.t_system_user WHERE loginName = ? ");
		StringBuffer sqlb = new StringBuffer("SELECT * FROM RQOAB.dbo.t_system_user WHERE loginName = ? ");
		StringBuffer sqlc = new StringBuffer("SELECT * FROM RQOAC.dbo.t_system_user WHERE loginName = ? ");
		StringBuffer sqls = new StringBuffer("SELECT * FROM RQOAS.dbo.t_system_user WHERE loginName = ? ");*/
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
		criteria.add(Restrictions.eq("loginName", loginname));		
		/*List<TSystemUser> rqoaaList =  rQSOAAspringDao.selectSQLQuery(sqla.toString(), new ParameterizedRowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				TSystemUser systemUser = new TSystemUser();
				systemUser.setUserId(arg0.getInt("userId"));
				return systemUser;
			}
			
		}, new Object[]{loginname});
		List<TSystemUser> rqoabList =  rQSOAAspringDao.selectSQLQuery(sqlb.toString(), new ParameterizedRowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				TSystemUser systemUser = new TSystemUser();
				systemUser.setUserId(arg0.getInt("userId"));
				return systemUser;
			}
			
		}, new Object[]{loginname});
		List<TSystemUser> rqoacList =  rQSOAAspringDao.selectSQLQuery(sqlc.toString(), new ParameterizedRowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				TSystemUser systemUser = new TSystemUser();
				systemUser.setUserId(arg0.getInt("userId"));
				return systemUser;
			}
			
		}, new Object[]{loginname});
		List<TSystemUser> rqoasList =  rQSOAAspringDao.selectSQLQuery(sqls.toString(), new ParameterizedRowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				TSystemUser systemUser = new TSystemUser();
				systemUser.setUserId(arg0.getInt("userId"));
				return systemUser;
			}
			
		}, new Object[]{loginname});*/
		if (qbcDao.getCriteria(criteria).size() > 0 ) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * 判断用户名是否重名
	 * @param 登录名
	 * @return
	 */
	public Boolean isSameUserName(String username){
//		StringBuffer sqla = new StringBuffer("SELECT * FROM RQOAA.dbo.t_system_user WHERE userName = ? ");
//		StringBuffer sqlb = new StringBuffer("SELECT * FROM RQOAB.dbo.t_system_user WHERE userName = ? ");
//		StringBuffer sqlc = new StringBuffer("SELECT * FROM RQOAC.dbo.t_system_user WHERE userName = ? ");
//		StringBuffer sqls = new StringBuffer("SELECT * FROM RQOAS.dbo.t_system_user WHERE userName = ? ");
//		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
//		criteria.add(Restrictions.eq("userName", username));		
//		List<TSystemUser> rqoaaList =  rQSOAAspringDao.selectSQLQuery(sqla.toString(), new ParameterizedRowMapper(){
//
//			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//				// TODO Auto-generated method stub
//				TSystemUser systemUser = new TSystemUser();
//				systemUser.setUserId(arg0.getInt("userId"));
//				return systemUser;
//			}
//			
//		}, new Object[]{username});
//		List<TSystemUser> rqoabList =  rQSOAAspringDao.selectSQLQuery(sqlb.toString(), new ParameterizedRowMapper(){
//
//			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//				// TODO Auto-generated method stub
//				TSystemUser systemUser = new TSystemUser();
//				systemUser.setUserId(arg0.getInt("userId"));
//				return systemUser;
//			}
//			
//		}, new Object[]{username});
//		List<TSystemUser> rqoacList =  rQSOAAspringDao.selectSQLQuery(sqlc.toString(), new ParameterizedRowMapper(){
//
//			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//				// TODO Auto-generated method stub
//				TSystemUser systemUser = new TSystemUser();
//				systemUser.setUserId(arg0.getInt("userId"));
//				return systemUser;
//			}
//			
//		}, new Object[]{username});
//		
//		List<TSystemUser> rqoasList =  rQSOAAspringDao.selectSQLQuery(sqls.toString(), new ParameterizedRowMapper(){
//
//			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//				// TODO Auto-generated method stub
//				TSystemUser systemUser = new TSystemUser();
//				systemUser.setUserId(arg0.getInt("userId"));
//				return systemUser;
//			}
//			
//		}, new Object[]{username});
//		if (qbcDao.getCriteria(criteria).size() > 0 || rqoaaList.size() > 0 || rqoabList.size() > 0 || rqoacList.size() > 0 || rqoasList.size() > 0) {
//			return true;
//		} else {
			return false;
//		}
	}
	
	public String getUserRoles(Integer systemUserID){
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TSystemUserRole.class);
		detachedCriteria.add(Restrictions.eq("userId", systemUserID));
		List<TSystemUserRole> userRoleList=qbcDao.getCriteria(detachedCriteria);
		StringBuffer rolesSB=new StringBuffer();
		for (TSystemUserRole systemUserRole : userRoleList) {
			rolesSB.append(","+systemUserRole.getRoleId()+",");
		}
		DetachedCriteria detachedCriteria2 = DetachedCriteria.forClass(TSystemUserRoleGroup.class);
		detachedCriteria2.add(Restrictions.eq("userId", systemUserID));
		List<TSystemUserRoleGroup> SystemUserRoleGroupList = qbcDao.getCriteria(detachedCriteria2);
		List<Integer> roleGroupIdList = new ArrayList<Integer>();
		for (TSystemUserRoleGroup systemUserRoleGroup : SystemUserRoleGroupList) {
			roleGroupIdList.add(systemUserRoleGroup.getRoleGroupId()); 			
		}
		for (Integer rolesGroupId : roleGroupIdList) {
			TSystemRolesGroup systemRolesGroup = systemRolesGroupBO.selectById(rolesGroupId);
			rolesSB.append(systemRolesGroup.getPermission());
			
		}
		
		return rolesSB.toString();
	}

	public String[] selectUserByDepartmentAndPostName(
			String[] departmentId, String postName) {
		// TODO Auto-generated method stub
		List<Integer >  useridlist =  new ArrayList<Integer>();
		List<Integer >  useridlist2 =  new ArrayList<Integer>();
		List<TSystemUser> systemuserlist2  =  selectByPostName(postName);
		for (TSystemUser systemUser2 : systemuserlist2) {
			useridlist2.add(systemUser2.getUserId());
		}
		for (String id : departmentId) {
			List<TSystemUser> systemuserlist  = selectByDepartment(id);
			for (TSystemUser systemUser : systemuserlist) {
				useridlist.add(systemUser.getUserId());
			}
			
		}
		useridlist.retainAll(useridlist2);
		String[] useridarray = new String[useridlist.size()];
		for(int i =0;i<useridlist.size() ;i++)
		{
			useridarray[i] = useridlist.get(i).toString();
		}
		return useridarray;
	}

	public List<TSystemUser> selectByPostName(String postName) {
		// TODO Auto-generated method stub
		List<TSystemUser> systemUserPostList = new ArrayList<TSystemUser>();
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemPost.class);
		criteria.add(Restrictions.eq("postName", postName ));
		List<TSystemPost> systemPostlist =	qbcDao.getCriteria(criteria);
		if (systemPostlist.size() >0) {
			TSystemPost systemPost =  systemPostlist.get(0);
			systemUserPostList = selectByPost(systemPost.getPostId());
		}
		List<TSystemUser> list = new ArrayList<TSystemUser>();
		for (TSystemUser systemUserPost : systemUserPostList) {
			TSystemUser systemUser = systemUserDao.findById(systemUserPost.getUserId());
			list.add(systemUser);
		}
		return list;
	}
	public String[] selectUserByDepartmentAndMultiPostName(String[] departmentId){
		String neiqin = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengshouwen/properties/systemResource_zh_CN.properties", this)
		.getProperty("xingzhengshouwen.neiqin");
		String zhubuzhang = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengshouwen/properties/systemResource_zh_CN.properties", this)
		.getProperty("xingzhengshouwen.zhubuzhang");
		String fubuzhang = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengshouwen/properties/systemResource_zh_CN.properties", this)
		.getProperty("xingzhengshouwen.fubuzhang");
		List<Integer >  useridlist =  new ArrayList<Integer>();
		List<Integer >  useridlist2 =  new ArrayList<Integer>();
		for (String id : departmentId) {
			Boolean isselect = false; //是否有
			List<TSystemUser> systemuserlist  = selectByDepartment(id);
			for (TSystemUser systemUser : systemuserlist) {
				if(isUserPost(systemUser.getUserId(),neiqin)){
					useridlist2.add(systemUser.getUserId());
					isselect = true;
				}
						
			}
			if(!isselect){
				for (TSystemUser systemUser : systemuserlist) {
					if(isUserPost(systemUser.getUserId(),zhubuzhang)){
						useridlist2.add(systemUser.getUserId());
						isselect = true;
					}
				}
			}
			if(!isselect){
				for (TSystemUser systemUser : systemuserlist) {
					if(isUserPost(systemUser.getUserId(),fubuzhang)){
						useridlist2.add(systemUser.getUserId());
						isselect = true;
					}
				}
			}
			if(!isselect && systemuserlist.size() > 0){
				useridlist2.add(systemuserlist.get(0).getUserId());
				isselect = true;
			}
		}
		String[] useridarray = new String[useridlist.size()];
		for(int i =0;i<useridlist.size() ;i++)
		{
			useridarray[i] = useridlist.get(i).toString();
		}
		return useridarray;
	}
	/**
	 * 判断用户是否有这个岗位
	 * @param 用户ID
	 * @param 岗位名称
	 * @return
	 */
	public Boolean isUserPost(Integer userid,String postName){
		List<TSystemUserPost> list = systemUserPostBO.selectByUserId(userid);
		for (TSystemUserPost systemUserPost : list) {
			if(systemUserPost.getPostName().equals(postName))
			{
				return true;
			}
		}
		return false;
	}
	/**
	 * 判断用户是否有这个职位
	 * @param 用户ID
	 * @param 岗位名称
	 * @return
	 */
	public Boolean isUserDuty(Integer userid,String dutyName){
		List<TSystemUserDuty> list = systemUserDutyBo.selectByUserId(userid);
		for (TSystemUserDuty systemUserDuty : list) {
			if(systemUserDuty.getDutyName().equals(dutyName))
			{
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 判断用户是否有这个职位级别
	 * @param 用户ID
	 * @param 职位级别
	 * @return
	 */
	public Boolean isUserDutyLevel(Integer userid,Integer levelNo){
		List<TSystemUserDuty> list = systemUserDutyBo.selectByUserId(userid);
		for (TSystemUserDuty systemUserDuty : list) {
			if(systemUserDuty !=null){
				TSystemDuty duty = systemDutyBo.findById(systemUserDuty.getDutyId());
				if( levelNo.equals(duty.getLevelNo()))
				{
					return true;
				}
			}
			
		}
		return false;
	}

	public ISystemDutyBo getSystemDutyBo() {
		return systemDutyBo;
	}

	public void setSystemDutyBo(ISystemDutyBo systemDutyBo) {
		this.systemDutyBo = systemDutyBo;
	}

	public List<TSystemUser> findByLikePermission(Integer role) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserRole.class);
		criteria.add(Restrictions.eq("roleId", role));
		List list = qbcDao.getCriteria(criteria);
		List<TSystemUser> listUser = new ArrayList<TSystemUser>(); 
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			TSystemUserRole userRole = (TSystemUserRole) iterator.next();
			TSystemUser user = this.findByIdSystemUser(userRole.getUserId());
			if (user.getState()==0) {
				listUser.add(user);
			}
		}
		return listUser;
	}

	public List<TSystemUser> selectAllSystemUser() {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
		List<TSystemUser> systemUserList = qbcDao.getCriteria(criteria);
		return systemUserList;
	}
	
	//部门下所有用户（包括所有下属部门）
	public List<TSystemUser> findByMainDepartment(String departmentId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemDepartment.class);
		SimpleExpression a = Restrictions.like("id", departmentId+"%");
		criteria.add(a);
		List<TSystemDepartment> list = qbcDao.getCriteria(criteria);
		
		List<TSystemUser> returnList = new ArrayList<TSystemUser>();
		List<TSystemUser> aa = this.selectByDepartment(departmentId.toString());
		for (Iterator iterator2 = aa.iterator(); iterator2
			.hasNext();) {
			TSystemUser user = (TSystemUser) iterator2.next();
			returnList.add(user);
		}
		
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			TSystemDepartment department = (TSystemDepartment) iterator.next();
			aa = this.selectByDepartment(department.getId());
			for (Iterator iterator2 = aa.iterator(); iterator2
					.hasNext();) {
				TSystemUser user = (TSystemUser) iterator2.next();
				returnList.add(user);
			}
			
		}
		return returnList;
	}
	
	public List<TSystemUser> findInUserIds(Integer[] users) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
		criteria.add(Restrictions.in("userId", users));
		criteria.addOrder(Order.asc("orderNo"));
		List<TSystemUser> systemUserList = qbcDao.getCriteria(criteria);
		return systemUserList;
	}
	
	/**
	 * 对用户ID集合根据OrderId进行排序
	 * @param userIdList 用户ID集合
	 * @return
	 */
	public List<String> userlistOrdery(List<String> userIdList){
		List<Integer> listId = new ArrayList<Integer>();		
		for (int i = 0; i < userIdList.size(); i++) {
			if(userIdList.get(i) != null && !"".equals(userIdList.get(i))){
				listId.add(Integer.parseInt(userIdList.get(i)));
			}
		}
		Integer userIdArray[] = listId.toArray(new Integer[1]);
		List<TSystemUser> systemUserList = findInUserIds(userIdArray);
		List<String> list = new ArrayList<String>();
		for(Integer userId : userIdArray) {
			list.add(userId.toString());
		}
		return list;
	}
	
	/**
	 * 根据ID查询一个系统用户附加的二级公司账户
	 * @param ID
	 * @return 系统用户
	 */
	public TSystemUser findByIdSystemUserErJiGongSi(Integer dataBaseId,Integer erjiuserid){
		StringBuffer sql = new StringBuffer("SELECT userId,loginName  FROM dbo.t_system_user WHERE userId = ?  ");
		List<TSystemUser> systemUserList = new ArrayList<TSystemUser>();
//		if (dataBaseId == 2) {
//			systemUserList = rQSOAAspringDao.querySQL(sql.toString(), new Object[]{erjiuserid}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1)
//						throws SQLException {
//					// TODO Auto-generated method stub
//					TSystemUser  systemUser = new TSystemUser ();
//					systemUser.setUserId(arg0.getInt("userId"));
//					systemUser.setLoginName(arg0.getString("loginName"));
//					return systemUser;
//				}
//				
//			});
//		}else if (dataBaseId == 3) {
//			systemUserList = rQSOABspringDao.querySQL(sql.toString(), new Object[]{erjiuserid}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1)
//						throws SQLException {
//					// TODO Auto-generated method stub
//					TSystemUser  systemUser = new TSystemUser ();
//					systemUser.setUserId(arg0.getInt("userId"));
//					systemUser.setLoginName(arg0.getString("loginName"));
//					return systemUser;
//				}
//				
//			});
//		}else if (dataBaseId == 4) {
//			systemUserList = rQSOACspringDao.querySQL(sql.toString(), new Object[]{erjiuserid}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1)
//						throws SQLException {
//					// TODO Auto-generated method stub
//					TSystemUser  systemUser = new TSystemUser ();
//					systemUser.setUserId(arg0.getInt("userId"));
//					systemUser.setLoginName(arg0.getString("loginName"));
//					return systemUser;
//				}
//				
//			});
//		}else if (dataBaseId == 5) {
//			systemUserList = rQSOAsspringDao.querySQL(sql.toString(), new Object[]{erjiuserid}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1)
//						throws SQLException {
//					// TODO Auto-generated method stub
//					TSystemUser  systemUser = new TSystemUser ();
//					systemUser.setUserId(arg0.getInt("userId"));
//					systemUser.setLoginName(arg0.getString("loginName"));
//					return systemUser;
//				}
//				
//			});
//		}
//		if (systemUserList.size() > 0 ) {
//			return systemUserList.get(0);
//		} else {
			return new TSystemUser();
//		}
	}
	
	public TSystemUser findByLoginName(String loginName){
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
		criteria.add(Restrictions.eq("loginName", loginName));
		return (TSystemUser) qbcDao.getCriteria(criteria).get(0);
	}
	
	/**
	 * 根据用户ID查询用户上级部门发文待办
	 * @param userId
	 * @return
	 */
	public List<TXingzhengfawenNeirong> selectXingZhengFaWenSuperDaiBanList(final Integer subDataBase, Integer dataBaseId, Integer userId,String proname){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT taskins.ID_ AS taskid,taskins.PROCINST_ AS flowid,fawenneirong.id AS docid, fawenneirong.biaoti AS biaoti,fawenneirong.zhusong AS zhusong,fawenneirong.chaosong AS chaosong ");
		sql.append("FROM dbo.JBPM_PROCESSDEFINITION AS prodefin JOIN  ");
		sql.append("dbo.JBPM_PROCESSINSTANCE AS proins ON prodefin.ID_ = proins.PROCESSDEFINITION_ JOIN   ");
		sql.append("dbo.JBPM_TASKINSTANCE AS taskins ON taskins.PROCINST_ = proins.ID_ JOIN   ");
		sql.append("dbo.t_system_user AS  userinfo ON  userinfo.userId  = taskins.ACTORID_ JOIN   ");
		sql.append("dbo.t_xingzhengfawen_neirong AS  fawenneirong ON fawenneirong.flowid = taskins.PROCINST_   ");
		sql.append("WHERE prodefin.NAME_ = ?    ");
		sql.append("AND userinfo.dataBaseId  = ?     ");
		sql.append("AND userinfo.subUserId = ?     ");
		sql.append("AND taskins.ISOPEN_ = 1 AND taskins.ISSIGNALLING_ = 1      ");
		List<TXingzhengfawenNeirong> xingzhengfawenNeirongList =   null;
//		if(subDataBase == 2){
//			xingzhengfawenNeirongList =  rQSOAAspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TXingzhengfawenNeirong xingzhengfawenNeirong = new TXingzhengfawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 3){
//			xingzhengfawenNeirongList =  rQSOABspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TXingzhengfawenNeirong xingzhengfawenNeirong = new TXingzhengfawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 4){
//			xingzhengfawenNeirongList =  rQSOACspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TXingzhengfawenNeirong xingzhengfawenNeirong = new TXingzhengfawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 5){
//			xingzhengfawenNeirongList =  rQSOAsspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TXingzhengfawenNeirong xingzhengfawenNeirong = new TXingzhengfawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}
		
		
		return xingzhengfawenNeirongList;
	}
	
	/**
	 * 根据用户ID查询用户上级部门发文待办
	 * @param userId
	 * @return
	 */
	public List<TDangweifawenNeirong> selectDangWeiFaWenSuperDaiBanList(final Integer subDataBase,Integer dataBaseId, Integer userId,String proname){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT taskins.ID_ AS taskid,taskins.PROCINST_ AS flowid,fawenneirong.id AS docid, fawenneirong.biaoti AS biaoti,fawenneirong.zhusong AS zhusong,fawenneirong.chaosong AS chaosong ");
		sql.append("FROM dbo.JBPM_PROCESSDEFINITION AS prodefin JOIN  ");
		sql.append("dbo.JBPM_PROCESSINSTANCE AS proins ON prodefin.ID_ = proins.PROCESSDEFINITION_ JOIN   ");
		sql.append("dbo.JBPM_TASKINSTANCE AS taskins ON taskins.PROCINST_ = proins.ID_ JOIN   ");
		sql.append("dbo.t_system_user AS  userinfo ON  userinfo.userId  = taskins.ACTORID_ JOIN   ");
		sql.append("dbo.t_dangweifawen_neirong AS  fawenneirong ON fawenneirong.flowid = taskins.PROCINST_   ");
		sql.append("WHERE prodefin.NAME_ = ?    ");
		sql.append("AND userinfo.dataBaseId  = ?     ");
		sql.append("AND userinfo.subUserId = ?     ");
		sql.append("AND taskins.ISOPEN_ = 1 AND taskins.ISSIGNALLING_ = 1      ");
		List<TDangweifawenNeirong> xingzhengfawenNeirongList =   null;
//		if(subDataBase == 2){
//			xingzhengfawenNeirongList =  rQSOAAspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TDangweifawenNeirong xingzhengfawenNeirong = new TDangweifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 3){
//			xingzhengfawenNeirongList =  rQSOABspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TDangweifawenNeirong xingzhengfawenNeirong = new TDangweifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 4){
//			xingzhengfawenNeirongList =  rQSOACspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TDangweifawenNeirong xingzhengfawenNeirong = new TDangweifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 5){
//			xingzhengfawenNeirongList =  rQSOAsspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TDangweifawenNeirong xingzhengfawenNeirong = new TDangweifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}
		return xingzhengfawenNeirongList;
	}
	
	
	/**
	 * 根据用户ID查询用户上级部门发文待办
	 * @param userId
	 * @return
	 */
//	public List<TTongzhifawenNeirong> selectTongZhiFaWenSuperDaiBanList(final Integer subDataBase,Integer dataBaseId, Integer userId,String proname){
//		StringBuffer sql = new StringBuffer();
//		sql.append("SELECT taskins.ID_ AS taskid,taskins.PROCINST_ AS flowid,fawenneirong.id AS docid, fawenneirong.biaoti AS biaoti,fawenneirong.zhusong AS zhusong,fawenneirong.chaosong AS chaosong ");
//		sql.append("FROM dbo.JBPM_PROCESSDEFINITION AS prodefin JOIN  ");
//		sql.append("dbo.JBPM_PROCESSINSTANCE AS proins ON prodefin.ID_ = proins.PROCESSDEFINITION_ JOIN   ");
//		sql.append("dbo.JBPM_TASKINSTANCE AS taskins ON taskins.PROCINST_ = proins.ID_ JOIN   ");
//		sql.append("dbo.t_system_user AS  userinfo ON  userinfo.userId  = taskins.ACTORID_ JOIN   ");
//		sql.append("dbo.t_tongzhifawen_neirong AS  fawenneirong ON fawenneirong.flowid = taskins.PROCINST_   ");
//		sql.append("WHERE prodefin.NAME_ = ?    ");
//		sql.append("AND userinfo.dataBaseId  = ?     ");
//		sql.append("AND userinfo.subUserId = ?     ");
//		sql.append("AND taskins.ISOPEN_ = 1 AND taskins.ISSIGNALLING_ = 1      ");
//		List<TTongzhifawenNeirong> xingzhengfawenNeirongList =   null;
//		if(subDataBase == 2){
//			xingzhengfawenNeirongList =  rQSOAAspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TTongzhifawenNeirong xingzhengfawenNeirong = new TTongzhifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 3){
//			xingzhengfawenNeirongList =  rQSOABspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TTongzhifawenNeirong xingzhengfawenNeirong = new TTongzhifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 4){
//			xingzhengfawenNeirongList =  rQSOACspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TTongzhifawenNeirong xingzhengfawenNeirong = new TTongzhifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}else if(subDataBase == 5){
//			xingzhengfawenNeirongList =  rQSOAsspringDao.querySQL(sql.toString(),  new Object[]{proname,dataBaseId,userId}, new RowMapper(){
//
//				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//					// TODO Auto-generated method stub
//					TTongzhifawenNeirong xingzhengfawenNeirong = new TTongzhifawenNeirong();
//					xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//					xingzhengfawenNeirong.setId(arg0.getString("docid"));
//					xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//					xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//					xingzhengfawenNeirong.setTaskId(Long.valueOf(arg0.getInt("taskid")));
//					xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//					xingzhengfawenNeirong.setDataBaseId(subDataBase);
//					xingzhengfawenNeirong.setDangqianhuanjie("封发");
//					return xingzhengfawenNeirong;
//				}
//				
//			});
//		}
//		return xingzhengfawenNeirongList;
//		return null;
//	}
	public Boolean endTask(Integer dataBaseId, Integer taskId){
//		String dataBaseName = "";
//		if (dataBaseId == 2 ) {
//			dataBaseName = "RQOAA"; 
//		}else if (dataBaseId == 3 ) {
//			dataBaseName = "RQOAB"; 
//		}else if (dataBaseId == 4 ) {
//			dataBaseName = "RQOAC"; 
//		}else if (dataBaseId == 5 ) {
//			dataBaseName = "RQOAS"; 
//		}
//		
//		
//		StringBuffer sql = new StringBuffer();
//		sql.append("UPDATE "+dataBaseName+".dbo.JBPM_TASKINSTANCE  ");
//		sql.append("SET ISOPEN_ = 0,ISSIGNALLING_  = 0   ");
//		sql.append("WHERE ID_ = ?  ");
//		rQSOAAspringDao.commonUpdate(sql.toString(), new Object[]{taskId});
		return true;
	
	}
	
	/**
	 * 查询下一级发文内容
	 * @param id
	 * @return
	 */
	public TXingzhengfawenNeirong selectDownXingZhengFaWei(Integer dataBaseId,String id){
//		StringBuffer sql = new StringBuffer();
//		String dataBaseName = "";
//		if (dataBaseId == 2 ) {
//			dataBaseName = "RQOAA";
//		}else if (dataBaseId == 3 ) {
//			dataBaseName = "RQOAB";
//		}else if (dataBaseId == 4 ) {
//			dataBaseName = "RQOAC";
//		} else if (dataBaseId == 5 ) {
//			dataBaseName = "RQOAS";
//		}  
//		sql.append("SELECT * FROM "+dataBaseName+".dbo.t_xingzhengfawen_neirong  WHERE id =  ?");
//		List<TXingzhengfawenNeirong> xingzhengfawenNeirongList =  rQSOAAspringDao.querySQL(sql.toString(),  new Object[]{id}, new RowMapper(){
//
//			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//				// TODO Auto-generated method stub
//				TXingzhengfawenNeirong xingzhengfawenNeirong = new TXingzhengfawenNeirong();
//				xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//				xingzhengfawenNeirong.setId(arg0.getString("id"));
//				xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//				xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//				xingzhengfawenNeirong.setChaobao(arg0.getString("chaobao"));
//				xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//				xingzhengfawenNeirong.setZhutici(arg0.getString("zhutici"));
//				xingzhengfawenNeirong.setNigaorenname(arg0.getString("nigaorenname"));
//				xingzhengfawenNeirong.setFujian(arg0.getString("fujian"));
//				xingzhengfawenNeirong.setWenhaotype(arg0.getString("wenhaotype"));
//				xingzhengfawenNeirong.setFawendatetime(arg0.getDate("fawendatetime"));
//				xingzhengfawenNeirong.setFenshu(arg0.getString("fenshu"));
//				xingzhengfawenNeirong.setDocname(arg0.getString("docname"));
//				xingzhengfawenNeirong.setQiChaoShiJian(new Date());
//				xingzhengfawenNeirong.setState(arg0.getInt("state"));
//				return xingzhengfawenNeirong;
//			}
//			
//		});
//		
//		return xingzhengfawenNeirongList.get(0);
		return null;
	}
	
	/**
	 * 查询下一级发文内容
	 * @param id
	 * @return
	 */
	public TDangweifawenNeirong selectDownDangWeiFaWei(Integer dataBaseId,String id){
//		StringBuffer sql = new StringBuffer();
//		String dataBaseName = "";
//		if (dataBaseId == 2 ) {
//			dataBaseName = "RQOAA";
//		}else if (dataBaseId == 3 ) {
//			dataBaseName = "RQOAB";
//		}else if (dataBaseId == 4 ) {
//			dataBaseName = "RQOAC";
//		} else if (dataBaseId == 5 ) {
//			dataBaseName = "RQOAS";
//		}  
//		sql.append("SELECT * FROM "+dataBaseName+".dbo.t_dangweifawen_neirong  WHERE id =  ?");
//		List<TDangweifawenNeirong> xingzhengfawenNeirongList =  rQSOAAspringDao.querySQL(sql.toString(),  new Object[]{id}, new RowMapper(){
//
//			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//				// TODO Auto-generated method stub
//				TDangweifawenNeirong xingzhengfawenNeirong = new TDangweifawenNeirong();
//				xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//				xingzhengfawenNeirong.setId(arg0.getString("id"));
//				xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//				xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//				xingzhengfawenNeirong.setChaobao(arg0.getString("chaobao"));
//				xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//				xingzhengfawenNeirong.setZhutici(arg0.getString("zhutici"));
//				xingzhengfawenNeirong.setNigaorenname(arg0.getString("nigaorenname"));
//				xingzhengfawenNeirong.setFujian(arg0.getString("fujian"));
//				xingzhengfawenNeirong.setWenhaotype(arg0.getString("wenhaotype"));
//				xingzhengfawenNeirong.setFawendatetime(arg0.getDate("fawendatetime"));
//				xingzhengfawenNeirong.setFenshu(arg0.getString("fenshu"));
//				xingzhengfawenNeirong.setDocname(arg0.getString("docname"));
//				xingzhengfawenNeirong.setState(arg0.getInt("state"));
//				return xingzhengfawenNeirong;
//			}
//			
//		});
//		
//		return xingzhengfawenNeirongList.get(0);
		return null;

	}
	
	/**
	 * 查询下一级发文内容
	 * @param id
	 * @return
	 */
//	public TTongzhifawenNeirong	 selectDownTongZhiFaWei(Integer dataBaseId,String id){
//		StringBuffer sql = new StringBuffer();
//		String dataBaseName = "";
//		if (dataBaseId == 2 ) {
//			dataBaseName = "RQOAA";
//		}else if (dataBaseId == 3 ) {
//			dataBaseName = "RQOAB";
//		}else if (dataBaseId == 4 ) {
//			dataBaseName = "RQOAC";
//		} else if (dataBaseId == 5 ) {
//			dataBaseName = "RQOAS";
//		}  
//		sql.append("SELECT * FROM "+dataBaseName+".dbo.t_tongzhifawen_neirong  WHERE id =  ?");
//		List<TTongzhifawenNeirong> xingzhengfawenNeirongList =  rQSOAAspringDao.querySQL(sql.toString(),  new Object[]{id}, new RowMapper(){
//
//			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
//				// TODO Auto-generated method stub
//				TTongzhifawenNeirong xingzhengfawenNeirong = new TTongzhifawenNeirong();
//				xingzhengfawenNeirong.setBiaoti(arg0.getString("biaoti"));
//				xingzhengfawenNeirong.setId(arg0.getString("id"));
//				xingzhengfawenNeirong.setZhusong(arg0.getString("zhusong"));
//				xingzhengfawenNeirong.setChaosong(arg0.getString("chaosong"));
//				//xingzhengfawenNeirong.setChaobao(arg0.getString("chaobao"));
//				xingzhengfawenNeirong.setFlowid(arg0.getInt("flowid"));
//				xingzhengfawenNeirong.setZhutici(arg0.getString("zhutici"));
//				xingzhengfawenNeirong.setNigaorenname(arg0.getString("nigaorenname"));
//				xingzhengfawenNeirong.setFujian(arg0.getString("fujian"));
//				xingzhengfawenNeirong.setWenhaotype(arg0.getString("wenhaotype"));
//				xingzhengfawenNeirong.setFawendatetime(arg0.getDate("fawendatetime"));
//				xingzhengfawenNeirong.setFenshu(arg0.getString("fenshu"));
//				xingzhengfawenNeirong.setDocname(arg0.getString("docname"));
//				xingzhengfawenNeirong.setStart(arg0.getInt("start"));
//				return xingzhengfawenNeirong;
//			}
//			
//		});
//		return xingzhengfawenNeirongList.get(0);
//		return null;
//	}
	
	
	/**
	 * 判断用户是否是该部门
	 * @param userId 用户ID
	 * @param departmentName 部门名称
	 * @return
	 */
	public Boolean selectUserInfoIsDepartment(Integer userId,String departmentName){
		List<Integer> list = new ArrayList<Integer>();
		StringBuffer sql = new StringBuffer(" SELECT COUNT(*)	AS count FROM  dbo.t_system_user  AS systemuser JOIN dbo.t_system_userDepartment AS userdepartment ");
		sql.append(" ON userdepartment.userId = systemuser.userId JOIN dbo.t_system_department AS department ");
		sql.append(" ON department.id = userdepartment.departmentId  ");
		sql.append(" WHERE systemuser.userId = ? AND department.deptName = ?  ");
		list = springDao.querySQL(sql.toString(), new Object[]{userId,departmentName}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				
				return arg0.getInt("count");
			}
			
		});
		
		if(list.get(0) == 0){
			return false;
		}else{
			return true;
		}
	}
	
	/**
	 * 授权封发
	 * @param userId
	 * @return
	 */
	public Boolean shouQuan(Integer mainId,Integer userId){
		StringBuffer sql = new StringBuffer("SELECT ID_ AS id  FROM dbo.JBPM_TASKINSTANCE WHERE ACTORID_ = ? AND NAME_ = ? AND END_ IS NULL ");
		List<Integer> list = new ArrayList<Integer>();
		list = springDao.querySQL(sql.toString(), new Object[]{userId,"封发"}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				
				return arg0.getInt("id");
			}
			
		});
		
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		for (Integer id : list) {
			workFlowTemplate.createTaskInstance(Long.valueOf(id.toString()), mainId.toString());
		}
		
		return true;
	}
	
	public Integer  selectTask(String userId,String processName){
		StringBuffer sql = new StringBuffer("SELECT COUNT(*) AS counttask FROM dbo.JBPM_TASKINSTANCE AS taskinstance JOIN dbo.JBPM_PROCESSINSTANCE AS processinstance ON ");
		sql.append("taskinstance.PROCINST_ = processinstance.ID_ JOIN dbo.JBPM_PROCESSDEFINITION AS processdefinition ON ");
		sql.append("processdefinition.ID_ = processinstance.PROCESSDEFINITION_ ");
		sql.append("WHERE taskinstance.ACTORID_ = ? AND taskinstance.ISOPEN_ = 1 AND taskinstance.ISSIGNALLING_ = 1 AND taskinstance.ISSUSPENDED_ = 0  AND processdefinition.NAME_ = ? ");
		List<Integer> countList = springDao.querySQL(sql.toString(), new Object[]{userId,processName}, new RowMapper(){

			
			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				return arg0.getInt("counttask");
				
			}
			
		});
		
		return countList.get(0);
	}

	public Integer selectHuiyi(String userId2,String userId3,String userId4) {
		
		StringBuffer sql = new StringBuffer();
		//sql.append("select ((select count(*) from t_meetingroom_employ where application_user_id=? and state=0 and meeting_time>=GETDATE()-1)");
		sql.append("select ((select count(*) from t_meetingroom_employ where examine_user_id=? and state=3 and meeting_time>=GETDATE()-1)");
		sql.append("+(select count(*) from t_meetingroom_incept i where receiveUser_id=? and state=0 and start_time >=GETDATE()-1)) as a,");
		sql.append("(select COUNT(*) from t_meetingroom_employ where examine_user_id like ? and state=3) as b");
		
		List<Integer> countList = springDao.querySQL(sql.toString(), new Object[]{","+userId2+",",userId3,userId4}, new RowMapper(){
			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				return arg0.getInt(1);
			}
		});
		return countList.get(0);
	}
}
